{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f2afde51",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.21.0\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "print(np.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5ebdce06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(1, 3)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4, 5, 6],\n",
       "       [7, 8, 9, 1, 2, 3]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[7, 8, 9, 1, 2, 3]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [7, 8, 9],\n",
       "       [4, 5, 6],\n",
       "       [1, 2, 3]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[7, 8, 9],\n",
       "       [1, 2, 3]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "np.r_是按列连接两个矩阵，就是把两矩阵上下相加，要求列数相等，类似于pandas中的concat()。\n",
    "np.c_是按行连接两个矩阵，就是把两矩阵左右相加，要求行数相等，类似于pandas中的merge()。\n",
    "\"\"\"\n",
    "\n",
    "# a是二维矩阵\n",
    "a = np.array([\n",
    "    [1, 2, 3],\n",
    "    [7, 8, 9]\n",
    "])\n",
    "b = np.array([\n",
    "    [4, 5, 6],\n",
    "    [1, 2, 3]\n",
    "])\n",
    "\n",
    "\n",
    "\n",
    "# c是三维向量\n",
    "# [[7, 8, 9]] 才是三个一维向量\n",
    "c = np.array([7, 8, 9])\n",
    "d = np.array([1, 2, 3])\n",
    "\n",
    "display(a.shape)\n",
    "display(c.shape)\n",
    "\n",
    "e = np.c_[a, b]\n",
    "display(e)\n",
    "\n",
    "\n",
    "f = np.c_[c, d]\n",
    "display(f)\n",
    "\n",
    "g = np.r_[a, b]\n",
    "display(g)\n",
    "\n",
    "h = np.r_[c, d]\n",
    "display(h)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
